var mapBoxEchart = echarts.init(document.getElementById('mapBox'));

var color = ['#46bee9'];
var series = [];
var res = [];
var lineData = [
    {
        "val": 1,
        "blat": 31.84,
        "blon": 117.14,
        "elat": 31.86,
        "elon": 117.11,
        "bcitysim": "德拓",
        "ecitysim": "航空新城"
    },
    {
        "val": 1,
        "blat": 31.84,
        "blon": 117.14,
        "elat": 31.868625,
        "elon": 117.491498,
        "bcitysim": "德拓",
        "ecitysim": "肥东"
    },
    {
        "val": 2,
        "blat": 31.862149,
        "blon": 117.11935,
        "elat": 31.868625,
        "elon": 117.491498,
        "bcitysim": "肥西",
        "ecitysim": "肥东"
    },
    {
        "val": 2,
        "blat": 31.9696,
        "blon": 117.365358,
        "elat": 31.899011,
        "elon": 117.243776,
        "bcitysim": "瑶海区",
        "ecitysim": "庐阳区"
    },

    {
        "val": 1,
        "blat": 31.9696,
        "blon": 117.365358,
        "elat": 31.251488,
        "elon": 117.289844,
        "bcitysim": "瑶海区",
        "ecitysim": "庐江县"
    }
];

var points = [
     {name:'德拓',value: [117.14, 31.84],itemStyle:{color:'#4fb6d2'}}
    , {name:'航空新城',value: [117.11, 31.86],itemStyle:{color:'#52b9c7'}}
    , {name:'肥西',value: [117.12935, 31.862149],itemStyle:{color:'#f56f1c'}}
    , {name:'肥东',value: [117.491498, 31.868625],itemStyle:{color:'#f56f1c'}}
    , {name:'德拓',value: [117.365358, 31.9696],itemStyle:{color:'#f56f1c'}}
    , {name:'庐江县',value: [117.289844, 31.251488],itemStyle:{color:'#f56f1c'}}

];


for (var i = 0; i < lineData.length; i++) {
    res.push({
        fromName: lineData[i].bcitysim,
        toName: lineData[i].ecitysim,
        coords: [
            [lineData[i].blon, lineData[i].blat],
            [lineData[i].elon, lineData[i].elat]
        ],
        count: lineData[i].val
    });

}
var planePath = 'path://M 512 512 m -160 0 a 160 160 0 1 0 320 0 a 160 160 0 1 0 -320 0 Z';


series.push(
    {
        //目的地
        name: {
            formatter: function (param) {
                return param.data.fromName
            }
        },

        type: 'lines',
        zlevel: 2,
        // lineStyle出发到目的地 的线条颜色
        lineStyle: {
            normal: {
                color:'#66CDAA'
                /* function (value){ //随机颜色

                ['#f21347','#f3243e','#f33736','#f34131','#f34e2b',
                '#f56321','#f56f1c','#f58414','#f58f0e','#f5a305',
                '#e7ab0b','#dfae10','#d5b314','#c1bb1f','#b9be23',
                '#a6c62c','#96cc34','#89d23b','#7ed741','#77d64c',
                '#71d162','#6bcc75','#65c78b','#5fc2a0','#5abead',
                '#52b9c7','#4fb6d2','#4ab2e5']
return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6);
}*/,
                width: 1, //线条宽度
                opacity: 0.1, //尾迹线条透明度
                curveness: 0.2 //尾迹线条曲直度
            }
        },

        // effect出发到目的地 的白色尾巴线条
        // 线特效的配置
        effect: {
            show: true,
            period: 4, //箭头指向速度，值越小速度越快
            trailLength: 0.4, //特效尾迹长度[0,1]值越大，尾迹越长重
            symbol: 'arrow', //箭头图标
            symbolSize: 7, //图标大小
            color:'#18E904' //图标颜色
        },
        label: {
            normal: {
                show: true,
                position: 'right',
                color: 'blue'
            }
        },
        tooltip: {
            formatter: function (param) {
                return param.data.fromName + '>' + param.data.toName + '<br>趟次：' + param.data.count
            }
        },
        data: res///开始到结束数据
    },
    {
        type: 'effectScatter',
        coordinateSystem: 'geo',
        showEffectOn: 'render',
        zlevel:1,
        rippleEffect: {
            period: 15,
            scale: 4,
            brushType: 'fill'
        },
        hoverAnimation: true,
        label: {
            normal: {
                formatter: '{b}',
                position: 'top',
                offset: [15, 0],
                color: '#fff',
                show: true
            },
        },
        itemStyle: {
            normal: {
                color:'#fff',
                shadowBlur: 10,
                shadowColor: '#333'
            }
        },
        symbolSize: 12,
        data:points //散点图数据
    },
);


option = {
    //backgroundColor: "#FBFAFC",
    legend: {
        show: true,
        selected: {},
        x: 'left',
        orient: 'vertical',
        textStyle: {
            color: 'white'
        },
        data: []
    },
    tooltip: {
        trigger: 'item',
        show: true,
    },
    toolbox: {
        show: false,
        orient: 'vertical',
        left: 'right',
        top: 'center',
        feature: {
            dataView: {
                readOnly: false
            },
            restore: {},
            saveAsImage: {}
        }
    },
    geo: {
        map: 'hefei',
        label: {
            normal: {
                show: true,
                textStyle: {
                    color: '#fff',
                    fontSize: 14,
                }
            },
            emphasis: {
                textStyle: {
                    color: '#fff'
                }
            }
        },
        emphasis: {
            show: true,
            color: '#fff'
        },
        top: 60,
        zoom: 1.1,
        roam: false,

        itemStyle: {
            normal: {
                borderColor: '#00D2E7',
                borderWidth: 1,
                areaColor: {
                    type: 'radial',
                    x: 0.5,
                    y: 0.5,
                    r: 0.8,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(0,210,231, 0)' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: 'rgba(0,210,231, .2)' // 100% 处的颜色
                    }],
                    globalCoord: false // 缺省为 false
                },
                shadowColor: 'rgba(128, 217, 248, 1)',
                // shadowColor: 'rgba(255, 255, 255, 1)',
                shadowOffsetX: -2,
                shadowOffsetY: 2,
                shadowBlur: 10
            },
            emphasis: {
                areaColor: 'rgba(0,210,231, .5)',
                borderWidth: 0
            }
        }
    },
    //series: series
};
// 使用制定的配置项和数据显示图表
mapBoxEchart.setOption(option);
// echart图表自适应
window.addEventListener("resize", function () {
    mapBoxEchart.resize();
});
